package com.ruoyi.manage.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.manage.domain.GOrganization;
import com.ruoyi.manage.service.IGOrganizationService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 管养单位信Controller
 * 
 * @author ruoyi
 * @date 2025-10-11
 */
@RestController
@RequestMapping("/manage/organization")
public class GOrganizationController extends BaseController
{
    @Autowired
    private IGOrganizationService gOrganizationService;

    /**
     * 查询管养单位信列表
     */
    @PreAuthorize("@ss.hasPermi('manage:organization:list')")
    @GetMapping("/list")
    public TableDataInfo list(GOrganization gOrganization)
    {
        startPage();
        List<GOrganization> list = gOrganizationService.selectGOrganizationList(gOrganization);
        return getDataTable(list);
    }

    /**
     * 导出管养单位信列表
     */
    @PreAuthorize("@ss.hasPermi('manage:organization:export')")
    @Log(title = "管养单位信", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, GOrganization gOrganization)
    {
        List<GOrganization> list = gOrganizationService.selectGOrganizationList(gOrganization);
        ExcelUtil<GOrganization> util = new ExcelUtil<GOrganization>(GOrganization.class);
        util.exportExcel(response, list, "管养单位信数据");
    }

    /**
     * 获取管养单位信详细信息
     */
    @PreAuthorize("@ss.hasPermi('manage:organization:query')")
    @GetMapping(value = "/{orgId}")
    public AjaxResult getInfo(@PathVariable("orgId") String orgId)
    {
        return success(gOrganizationService.selectGOrganizationByOrgId(orgId));
    }

    /**
     * 新增管养单位信
     */
    @PreAuthorize("@ss.hasPermi('manage:organization:add')")
    @Log(title = "管养单位信", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody GOrganization gOrganization)
    {
        return toAjax(gOrganizationService.insertGOrganization(gOrganization));
    }

    /**
     * 修改管养单位信
     */
    @PreAuthorize("@ss.hasPermi('manage:organization:edit')")
    @Log(title = "管养单位信", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody GOrganization gOrganization)
    {
        return toAjax(gOrganizationService.updateGOrganization(gOrganization));
    }

    /**
     * 删除管养单位信
     */
    @PreAuthorize("@ss.hasPermi('manage:organization:remove')")
    @Log(title = "管养单位信", businessType = BusinessType.DELETE)
	@DeleteMapping("/{orgIds}")
    public AjaxResult remove(@PathVariable String[] orgIds)
    {
        return toAjax(gOrganizationService.deleteGOrganizationByOrgIds(orgIds));
    }
}
